<template>
  <div class="rights">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card class="box-card">
      <el-table :data="getNum" border style="width: 100%">
        <el-table-column type="index" width="50" label="#"> </el-table-column>
        <el-table-column prop="authName" label="权限名称"> </el-table-column>
        <el-table-column prop="path" label="路径"> </el-table-column>
        <el-table-column prop="level" label="权限等级">
          <template slot-scope="scope">
            <el-tag :type="scope.row.level==0?'primary':scope.row.level==1?'success':'danger'">
            {{scope.row.level==0?'一级':scope.row.level==1?'二级':'三级'}}
           </el-tag>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
       <el-pagination
       @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="pagenum"
      :page-sizes="[10, 20, 30, 40]"
      :page-size.sync="pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="tableData.length">
    </el-pagination>
    </el-card>
  </div>
</template>
<script>
import { pleaList } from "../utils/http";
export default {
  data() {
    return {
      tableData: [],
      pagenum:1,   //当前页
      pagesize:10,  //每页条数
      total:0
    };
  },
  computed: {
    getNum () {
      return this.tableData.slice((this.pagenum-1)*this.pagesize,this.pagenum*this.pagesize)
    },
  },
  methods: {
    handleSizeChange(val) {
      this.pagesize=val
    },
    handleCurrentChange(val){
      this.pagenum=val
    }
  },
  created() {
    pleaList().then((res) => {
      console.log(res);
      if (res.meta.status == 200) {
        this.tableData = res.data;
        this.$message({
          type: "success",
          message: res.meta.msg,
        });
      } else {
        this.$message({
          type: "danger",
          message: res.meta.msg,
        });
      }
    });
  },
};
</script>
<style lang="scss" scoped>
::v-deep .el-breadcrumb {
  margin-bottom: 20px;
}
.el-pagination {
  margin-top: 20px;
}
</style>